define(function(require, exports, module) {

  // var Backbone = require('backbone');
  var $ = require('jquery');
  var _ = require('lodash');
  // var jsonview = require('jsonview');
  var tmpl = require('text!../tmpl.html');

  function Student(name) {
    // console.log('Before assign-this', this);
    this.name = name;
    // console.log('After assign-this', this);

    return 1
  }

  Student.prototype.doSth = function() {
    console.log(this.name);
  }

  function newOperator(clazz) {
    if (typeof clazz !== 'function') {
      throw "newOperator function the first param must be function"
    }

    const args = Array.prototype.slice.call(arguments, 1);

    const obj = {};
    const ret = clazz.apply(obj, args);
    if (typeof ret === 'object' || typeof ret === 'function') {
      return ret;
    }

    obj.__proto__ = clazz.prototype;

    return obj;

  }

  function app() {
    var student = new Student('DY');
    var student1 = new Student('DD');
    var student2 = new Student('YY');

    console.log(student, typeof student);
    console.log(Object.prototype.toString.call(student));

    var student3 = newOperator(Student, "DY");

    console.log(student3)
    console.log(Object.prototype.toString.call(student3));

    console.log(Object.getPrototypeOf(student3) === Student.prototype)

    console.log(student3, student3.doSth());

    console.log(student1, student1.doSth());
    console.log(student2, student2.doSth());
    
    // var obj = new Object();
    // console.log(obj);
    // console.log(Object.prototype.toString.call(obj));
  }

  function main() {
    var $app = $('<div id="app">');
    $('#main').html($app);
    app();
    $app.append(tmpl);
  }

  return main;
})
